package br.com.pocs.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import br.com.pocs.model.Client;

@Component
@Transactional(propagation = Propagation.REQUIRED)
public class ClientDao {
	@PersistenceContext
	private EntityManager entityManager;
	
	public void save(Client custom) {
		entityManager.merge(custom);
	}

	@SuppressWarnings("unchecked")
	public List<Client> listAll() {
		return entityManager.createQuery("from Client c").getResultList();
	}

	public Client load(Long id) {
		return entityManager.find(Client.class, id);
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}

	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

}
